/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interface;

import Negocio.CadastroEvent;
import Negocio.CadastroListener;
import Negocio.Categoria;
import java.util.ArrayList;
import java.util.List;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;

/**
 *
 * @author asouza
 * http://javafree.uol.com.br/topic-884470-Retornar-o-codigo-de-um-ComboBoxModel.html
 */
public class ComboModelCategoria extends AbstractListModel implements ComboBoxModel, CadastroListener{
    private List<Categoria> listaFuncoes = new ArrayList<Categoria>();  
    private Object selectedItem;
    
    public ComboModelCategoria(){  
    }
    
    public ComboModelCategoria(List<Categoria> dados){  
        listaFuncoes.addAll(dados);
    }
    
    @Override
    public int getSize() {
       return listaFuncoes.size();
    }

    @Override
    public Object getElementAt(int index) {
       return listaFuncoes.get(index);  
    }

    @Override
    public void setSelectedItem(Object anItem) {
        selectedItem = anItem;  
    }

    @Override
    public Object getSelectedItem() {
          return selectedItem;   
    }
     public void add(Categoria s) {
        listaFuncoes.add(s);
        fireIntervalAdded(this, listaFuncoes.size(), listaFuncoes.size());
    }

    @Override
    public void elementoAdicionado(CadastroEvent evt) {
        add((Categoria) evt.getObjetoEvento());
    }
    
}
